package com.starview.star.compiler.util;

import java.io.File;
import java.util.Iterator;

public class DirectoryIterator implements Iterator<File>
{
  private final File dir;
  private final String[] list;
  private int next = 0;

  public DirectoryIterator(File dir)
  {
    this.dir = dir;
    assert dir.isDirectory();
    this.list = dir.list();
  }

  @Override
  public boolean hasNext()
  {
    return next < list.length;
  }

  @Override
  public File next()
  {
    return new File(dir, list[next++]);
  }

  @Override
  public void remove()
  {
    new File(dir, list[next - 1]).delete();
  }
}
